#!/bin/sh
###############################################################################
# Version      :  0.01a (20th September 2006)
# Author       :  R2Hosting, Melbourne. Australia
# Contact      :  info@r2hosting.com.au
# This File    :  autoSiteRESTORE.sh
# Partner File :  autoSiteDUMP.sh
#
# Information/Overview:
# This is a quick and (very) dirty Application Demo Site MySQL Restore script.
# It is designed to be run through a crontab at your selected timeframe.
# It works in conjunction with the autoSiteDUMP.sh script.
#
# USAGE:
# Install your application(s), configure, add content, modify the application
# to the point where you are happy it contains the required demonstration data.
#
# ** This is a one-time (initial) activity only ** 
# Use the autoSiteDUMP.sh script to dump the SQL of the selected databases.
#
# ** Regular crontab based activity **
# Setup a crontab to run this script (autoSiteRESTORE.sh) to regularly
# reload the applications datbase with the previously dumped SQL.
# Your demo site is now restored back to the original installation state
# (being the state that the dBase was in when you dumped it previously)
# 
###############################################################################
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later 
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
# more details.
###############################################################################


# List all of the MySQL databases that you want to be RESTORED in here,
# Aach seperated by a space
databases="userone_demosite1 userone_demosite2"

# Directory where you want the backup files are stored
# Change <userone> to reflect your absolute path
restoreDir=/home/userone/demoSiteRefresh/MASTERdumps

# MySQL Username and password
# Change <your-master-SQL-username> and <your-master-SQL-Password> to your master dB password
# If only one dBase or same user and password for all dB's set it to this instead of the Master
userPassword=" --user=<your-master-SQL-username> --password=<your-master-SQL-Password>"

# Unix Commands
gzip=/bin/gzip

# Restore all of our databases
echo ""
DOW=`date`
echo "$DOW"
echo "RESTORING SITE DATABASES"
echo "_____________________________________________ "
echo ""
for db in $databases
do
   echo "----------------------------------------------"
   echo "Restoring $db MySQL Database"
   time zcat ${restoreDir}/$db.gz | mysql -C $db $userPassword
done
echo ""
echo "_____________________________________________ "
echo "Done..."
exit
